﻿using System;
using System.Text;
using System.Web.Security;
using wojilu.Web.Mvc.Attr;

namespace wojilu.Web.Controller
{
    public class YBBTestController : BaseTempController
    {
        public YBBTestController()
        {
            LayoutControllerType = typeof(YBBSiteInitController);
        }

        [NonVisit]
        public virtual void setpublic()
        {
            //set("top", loadHtml(new PublicController().Top));
            //set("bottom", loadHtml(new PublicController().Bottom));
        }

        [HttpGet]
        public virtual void Index()
        {
            string input = ctx.Get("domain");

            string[] strArray = input.Split(new char[] { '.' });
            int length = strArray.Length;
            if (length > 1)
            {
                string str = strArray[length - 2] + "." + strArray[length - 1];
                switch (str)
                {
                    case "org.cn":
                    case "gov.cn":
                    case "com.cn":
                    case "net.cn":
                        str = strArray[length - 3] + str;
                        break;
                }
                string str5 = md5(str, 0x10).Substring(0, 12);
                string str6 = md5(strArray[length - 1], 0x10).Substring(0, 8);
                string str7 = str5.Insert(4, str6);
                ctx.web.ResponseWrite(str7);
                ctx.web.ResponseEnd();
            }

        }

        /// <summary>
        /// 还原数字
        /// </summary>
        [HttpGet]
        public virtual void F()
        {
            var str = ctx.Get("str");
            ctx.web.ResponseWrite(smethod_2(str));
            ctx.web.ResponseEnd();
        }

        internal static string smethod_2(string string_0)
        {
            byte[] array = Convert.FromBase64String(string_0);
            return Encoding.Unicode.GetString(array, 0, array.Length);
        }

        public static string md5(string str, int code)
        {
            if (code == 0x10)
            {
                return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 0x10);
            }
            return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
        }

    }
}
